const cardmsg=/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
const phonemsg=/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;
const nameReg = /^([\u4e00-\u9fa5]+|([a-z]+\s?)+)$/;
const ChineseRge = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;

export const CardValidation = (rule:any, value:any, callback:any)=>{
	if (!value) {
	    return Promise.reject("身份证号码不能为空");
	}
	if (!cardmsg.test(value)){
	    return Promise.reject("身份证号码不符合规定");
	}
	return Promise.resolve();
};

export const CardNotValidation = (rule:any, value:any, callback:any)=>{
	if (!cardmsg.test(value) && value){
	    return Promise.reject("身份证号码不符合规定");
	}
	return Promise.resolve();
};

export const PhoneValidation = (rule:any, value:any, callback:any)=>{
	if (!value) {
	    return Promise.reject("请输入电话号码");
	}
	if (!phonemsg.test(value)){
	    return Promise.reject("请输入正确的电话号码");
	}
	return Promise.resolve();
};

export const NameValidation = (rule:any, value:any, callback:any)=>{
	if (!value) {
	    return Promise.reject("姓名不能为空");
	}
	if (!nameReg.test(value.trim())){
	    return Promise.reject("姓名请输入2~18位纯英文、中文组合");
	}
	return Promise.resolve();
};

export const NumberValidation = (rule:any, value:any, callback:any)=>{
	if (!value) {
	    return Promise.reject('工号不能为空');
	}
	if (ChineseRge.test(value)) {
	    return Promise.reject('工号不能含有汉字');
	}else if(/\s/g.test(value)){
		return Promise.reject('工号不能含有空格');
	}else{
		return Promise.resolve();
	}  
};